//
//  AppDelegate.m
//  singForYou
//
//  Created by nicolas on 2016/12/6.
//  Copyright © 2016年 nicolas. All rights reserved.
//

#import "AppDelegate.h"
#import "MKBaseTabBarController.h"
#import "MKLoginViewController.h"

#import <BaiduMapAPI_Base/BMKBaseComponent.h>

@interface AppDelegate ()<BMKGeneralDelegate>

@property (strong, nonatomic) BMKMapManager *manager;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //创建UIWindow
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    //设置window的根控制器
    //MKBaseTabBarController *baseTabBarController = [[MKBaseTabBarController alloc] init];
    
    MKLoginViewController *loginVc = [UIStoryboard storyboardWithName:@"MKLoginSb" bundle:nil].instantiateInitialViewController;
    
    self.window.rootViewController = loginVc;
    
    [self.window makeKeyAndVisible];
    
    //ios10之前
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIAlertControllerStyleAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
    
    _manager = [[BMKMapManager alloc] init];
    BOOL isSuccess = [_manager start:BaiduMapAppkey generalDelegate:self];
    if (isSuccess) {
        MKLog(@"百度地图启动成功");
    }
    
    return YES;
}

#pragma mark - BMKGeneralDelegate
- (void)onGetNetworkState:(int)iError {
    MKLog(@"%d",iError);
    if (iError == E_PERMISSION_OK) {
        MKLog(@"百度授权成功");
    }
}

#pragma mark - 远程推送的DeviceToken相关
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    
    NSLog(@"deviceToken : %@",deviceToken);
    //DeviceToken 013ed679 0f3313f1 ead3208f 53ee01f2 7b6b4930 5a66d14c c9056a4e e15573cb
}
//注册DeviceToken失败
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    
    NSLog(@"%@",error);
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

//App进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application {
    [application beginReceivingRemoteControlEvents];
}

//即将进入App触发
- (void)applicationWillEnterForeground:(UIApplication *)application {
    [application endReceivingRemoteControlEvents];
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
